<template>
	<div>
		<Head></Head>
		<el-row class="list"  v-for="(item,index) in bodys" >
			<el-col :span="9" >
				<img :src="item.pic" alt="">
			</el-col>
			<el-col :span="14" class="list-r">
				<span class="car-name">{{item.good_title}}&nbsp;</span>
				<span class="car-xx">{{formatDate(item.create_time)}}</span>
				<div class="list-b">
					<span>{{item.pay_amount}}万￥</span>
					<span v-if="item.state=='1'">订单已经支付</span>
					<span v-if="item.state=='2'">订单已经取消</span>
					<el-button type="warning" round  @click="pay(item,index)" v-if="item.state=='0'"  size="small">支付</el-button>
					<el-button type="warning" round  @click="cancle(item,index)" v-if="item.state=='0'" size="small">取消</el-button>
				</div>
			</el-col>
		</el-row>
	</div>
</template>

<script>
	import Head from "@/components/Head.vue"
	import EmptyBox from "@/components/EmptyBox.vue"
	import { selOrder,editOrder } from "../api/jsoup"
import { formatDate } from "../api/easyUtil"
	export default {
		name: "MyOrder",
		components: {
			Head,
			EmptyBox
		},
		data() {
			return {
				user:{},
				bodys:[],
			}
		},
		methods: {
			pay(item,index){
				this.$confirm(`是否支付订单号${item.id}, 是否继续?`, '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					editOrder({id:item.id,state:1},(data)=>{
						this.$message({
							message: '支付成功！',
							type: 'success'
						});
						this.bodys[index].state = '1';
					});
				}).catch(() => {
					this.$message({
						message: '请及时支付！',
						type: 'warning'
					});
				});
			},
			cancle(item,index){
				this.$confirm(`是否取消订单号${item.id}?`, '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					editOrder({id:item.id,state:2},(data)=>{
						this.$message({
							message: '取消订单成功！',
							type: 'success'
						});
						this.bodys[index].state = '2';
					});
				}).catch(() => {

				});
			}
		},
		mounted() {
			if($.cookie("user")) this.user = JSON.parse($.cookie("user"));	
			if(this.user.id!=undefined){

				selOrder({user_id:this.user.id},(data)=>{
					let res = eval("(" + data + ")");
					console.log(res);
					this.bodys = res;
				});
			}
		}

	}
</script>

<style>
</style>
